package com.ctshk.rpc.system.mapper;

import com.ctshk.rpc.system.entity.MainDataTourGroupArea;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ctshk.rpc.system.entity.MainDataTourGroupCode;
import com.ctshk.rpc.system.req.MainDataTourGroupAreaReq;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 旅游分组所属目的地表 Mapper 接口
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-02-05
 */
public interface MainDataTourGroupAreaMapper extends BaseMapper<MainDataTourGroupArea> {

    @Select({"<script>",
            "select tga.id,tga.code_id, tga.area_id, tga.area_name,tga.gmt_create,tga.create_id,tga.gmt_modified,tga.modified_id,tga.is_deleted",
            "from t_main_data_tour_group_area tga where is_deleted = 0 and area_id in",
            "<foreach collection='areaList' item='area' open='(' separator=',' close=')'>",
            "#{area.areaId}",
            "</foreach>",
            "</script>"
    })
    List<MainDataTourGroupArea> selectListByAreaList(List<MainDataTourGroupAreaReq> areaList);

    @Select({"<script>",
            "select id,code_id, area_id, area_name,gmt_create,create_id,gmt_modified,modified_id,is_deleted",
            "from t_main_data_tour_group_area  where is_deleted = 0 and code_id != #{id} tga.area_id in",
            "<foreach collection='areaList' item='area' open='(' separator=',' close=')'>",
            "#{area.areaId}",
            "</foreach>",
            "</script>"
    })
    List<MainDataTourGroupArea> selectListByAreaListAndId(List<MainDataTourGroupAreaReq> areaList, @Param("id") Long id);

    @Update({"update t_main_data_tour_group_area set is_deleted = 1 where area_id = #{areaId} and area_name = #{areaName}"})
    void updateIsDelete(@Param("areaId") Long areaId, @Param("areaName") String areaName);

}
